package client;

import java.awt.Color;

import javax.swing.*;

public class MyJLoginPanel extends JPanel {
	private static final long serialVersionUID = 4876678972838515799L;
	private JTextField username;
	private JPasswordField password;
	private JLabel errorLabel;

	public MyJLoginPanel(Control mlcc) {
		this.setLayout( null );
		this.setBounds(0, 0, 500, 500);
		this.setBackground(Color.lightGray);
		
		errorLabel = new JLabel();
		errorLabel.setBounds(30, 10, 300, 20);
		this.add(errorLabel);
		
		JLabel usernameLabel = new JLabel("Username");
		usernameLabel.setBounds(30, 30, 100, 20);
		this.add(usernameLabel);
		
		username = new JTextField();
		username.setBounds(130, 30, 200, 20);
		this.add(username);
		
		JLabel passwordLabel = new JLabel("Password");
		passwordLabel.setBounds(30, 60, 100, 20);
		this.add(passwordLabel);
		
		password = new JPasswordField();
		password.setBounds(130,60,200,20);
		password.addKeyListener(mlcc);
		this.add(password);
		
		JButton loginBtn = new JButton("Login");
		loginBtn.setBounds(170, 90, 75, 25);
		loginBtn.addActionListener(mlcc);
		this.add(loginBtn);
		JButton exitBtn = new JButton("Exit");
		exitBtn.setBounds(255, 90, 75, 25);
		exitBtn.addActionListener(mlcc);
		this.add(exitBtn);
	}
	
	public void setEnabled(boolean enabled) {
		this.setEnabled(enabled);
	}
	
	public void requestFocus(int i) {
		this.requestFocus(i);
	}
	
	public void setLabel(String newText) {
		errorLabel.setText(newText);
		errorLabel.setBounds(30, 10, 300,15);
		errorLabel.setForeground(Color.RED);
		errorLabel.repaint();
		errorLabel.validate();		
	}

	
	public String getUsr() {
		return username.getText();
	}
	
	public String getPwd() {
		return new String(password.getPassword());
	}
}
